<div id="view-content">
<?php include_once '/../supMenu.html';
      if (isset($_POST['cmdView'])){
	      //
	      // === Set commbox hien thi dung nguoi xem
		  $_REQUEST['teach-manager'] = $_POST['cbbTeachView'];
      }
?>
	<br>
	<h2 class="backend-h2"><span class="img"></span>
		<span> Phân môn học cho giáo viên</span>
    </h2>

    <p class="saporator"><br /></p>

    <div id="accordion">
    	<h3 class="tmc-teachmanager-title"><a href="#">Bổ sung môn học cho giáo viên</a></h3>
    	<div id="tmc-add">
    	   <form method="post" class="validate-form" action="<?php echo $this->baseUrl('/admin/tmc/add/');?>">
                <table>
                    <tr>
                        <td class="tmc-title-name">Chọn giáo viên </td>
                        <td>
                            <select id="tmc-teacher" name="cbbTeach">
                            <?php foreach ($this->teachs as $teach) {
                            	echo '<option value="'.$teach['username'].'">'.$teach['hoDem']." ".$teach['ten'].'</option>';
                            }
                            ?>
                            </select>
                        </td>
                    </tr>
                    
                    <tr>
                        <td class="tmc-title-name">Chọn lớp </td>
                        <td>
                            <select id="tmc-class" name="cbbClass">
                            <?php foreach ($this->lops as $lop) {
                            	echo '<option value="'.$lop['id'].'">'.$lop['tenLop'].'</option>';
                            }?>
                                
                            </select>
                        </td>
                    </tr>
                    
                    <tr>
                        <td class="tmc-title-name">Chọn môn học</td>
                        <td>
                            <select id="tmc-course" name="cbbCourse">
                            <?php foreach ($this->courses as $course) {
                            	echo '<option value="'.$course['id'].'">'.$course['tenMonHoc'].'</option>';
                            }?>
                            </select>
                        </td>
                    </tr>                    
                </table>
                
                <input class="tmc-submit" type="submit" value="Thêm môn quản lý" name="cmdAdd" />
           </form>
        		
    	</div><!-- End Bo sung mon học cho giao viên -->
    	
        <h3 class="tmc-viewinfo-title"><a href="#">Xem thông tin </a></h3>
    	<div id="tmc-viewinfo-content">    	   
			<form method="post" action="<?php echo $this->baseUrl('/admin/tmc/viewmanager'); ?>">
			    <label>Chọn giáo viên cần xem thông tin
			        <select id="tmc-teacher-view" class="teach-view" name="cbbTeachView">
			            <?php foreach ($this->teachs as $teach) {
			            	if(isset($_REQUEST['teach-manager']) 
			            		&& $_REQUEST['teach-manager'] == $teach['username']){
			            		echo '<option value="'.$teach['username'].'" selected="selected">'.$teach['hoDem']." ".$teach['ten'].'</option>';	
			            	}else{
			            		echo '<option value="'.$teach['username'].'">'.$teach['hoDem']." ".$teach['ten'].'</option>';
			            	}
			            }
			            ?>
			        </select>
			        <input type="submit" name="cmdView" value="Xem">
			    </label>
			</form>
			
			<br />
			
			<table class="view-teach-table">
			    <thead>
			        <tr>
			            <th>Mã lớp</th>
			            <th>Tên lớp</th>
                        <th>Môn học quản lý</th>
			            <th>Xóa</th>
			        </tr>
			    </thead>  
			    
			    <tbody>
			    <?php 
			    if (isset($this->managers)){
			    	foreach ($this->managers as $manager) {
			    ?>
			    	<tr>
			            <th><?php echo $manager['idLop'];?></th>
			            <th><?php echo $manager['tenLop'];?></th>
                        <th><?php echo $manager['tenMonHoc']; ?></th>
			            <th><a href="<?php echo $this->baseUrl('/admin/tmc/del/?course='.$manager['idMonHoc'].'&lop='.$manager['idLop'])?>">Xóa</a></th>
			        </tr>
			    <?php 
			    	}
			    }
			    ?>
			    </tbody>
			</table>         
    	</div><!-- End Xem thong tin accordinate -->
    	
    </div><!-- End .accordin -->    
</div>

<script>
        
    (function( $ ) {
		$.widget( "ui.combobox", {
			_create: function() {
				var self = this,
					select = this.element.hide(),
					selected = select.children( ":selected" ),
					value = selected.val() ? selected.text() : "";
				var input = this.input = $( "<input>" )
					.insertAfter( select )
					.val( value )
					.autocomplete({
						delay: 0,
						minLength: 0,
						source: function( request, response ) {
							var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
							response( select.children( "option" ).map(function() {
								var text = $( this ).text();
								if ( this.value && ( !request.term || matcher.test(text) ) )
									return {
										label: text.replace(
											new RegExp(
												"(?![^&;]+;)(?!<[^<>]*)(" +
												$.ui.autocomplete.escapeRegex(request.term) +
												")(?![^<>]*>)(?![^&;]+;)", "gi"
											), "<strong>$1</strong>" ),
										value: text,
										option: this
									};
							}) );
						},
						select: function( event, ui ) {
							ui.item.option.selected = true;
							self._trigger( "selected", event, {
								item: ui.item.option
							});
						},
						change: function( event, ui ) {
							if ( !ui.item ) {
								var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
									valid = false;
								select.children( "option" ).each(function() {
									if ( $( this ).text().match( matcher ) ) {
										this.selected = valid = true;
										return false;
									}
								});
								if ( !valid ) {
									// remove invalid value, as it didn't match anything
									$( this ).val( "" );
									select.val( "" );
									input.data( "autocomplete" ).term = "";
									return false;
								}
							}
						}
					})
					.addClass( "ui-widget ui-widget-content ui-corner-left" );

				input.data( "autocomplete" )._renderItem = function( ul, item ) {
					return $( "<li></li>" )
						.data( "item.autocomplete", item )
						.append( "<a>" + item.label + "</a>" )
						.appendTo( ul );
				};

				this.button = $( "<button type='button'>&nbsp;</button>" )
					.attr( "tabIndex", -1 )
					.attr( "title", "Show All Items" )
					.insertAfter( input )
					.button({
						icons: {
							primary: "ui-icon-triangle-1-s"
						},
						text: false
					})
					.removeClass( "ui-corner-all" )
					.addClass( "ui-corner-right ui-button-icon" )
					.click(function() {
						// close if already visible
						if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
							input.autocomplete( "close" );
							return;
						}

						// work around a bug (likely same cause as #5265)
						$( this ).blur();

						// pass empty string as value to search for, displaying all results
						input.autocomplete( "search", "" );
						input.focus();
					});
			},

			destroy: function() {
				this.input.remove();
				this.button.remove();
				this.element.show();
				$.Widget.prototype.destroy.call( this );
			}
		});
	})( jQuery );
    
	$(function() {
		$( "#accordion" ).accordion();
        $( "#tmc-teacher" ).combobox();
        $( "#tmc-course" ).combobox();
        $( "#tmc-class" ).combobox();
        
        $( "#tmc-teacher-view" ).combobox();
        $( ".teach-view").change(function(){
            //$('.ddd').load('/admin/tmc/test/');
            alert("Đfa fsdaf");
        });
        <?php 
        if (isset($_POST['cmdView'])){
        ?>
			$( ".tmc-viewinfo-title" ).click();
		<?php 
		}
        ?>
	});
</script>
<style>
    .ui-button { margin-left: -1px; }
    .ui-button-icon-only .ui-button-text { padding: 0.35em; } 
    .ui-autocomplete-input { margin: 0; padding: 0.48em 0 0.47em 0.45em; }
</style>
